package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsSpecificationMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.pojo.DtsGoodsSpecification;
import com.qf.service.DtsGoodsSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DtsGoodsSpecificationServiceImpl implements DtsGoodsSpecificationService {

    @Autowired
    DtsGoodsSpecificationMapper goodsSpecificationMapper;

    @Override
    public void update(Integer id, DtsGoodsSpecification[] specifications) {
        LambdaQueryWrapper<DtsGoodsSpecification> qw = new LambdaQueryWrapper<>();
        qw.eq(DtsGoodsSpecification::getGoodsId,id);
        goodsSpecificationMapper.delete(qw);

        if(specifications != null && specifications.length > 0){
            for (DtsGoodsSpecification specification : specifications) {
                specification.setAddTime(new Date());
                specification.setUpdateTime(new Date());
                specification.setGoodsId(id);
                goodsSpecificationMapper.insert(specification);
            }
        }
    }

    @Override
    public void delete(Integer id) {
        DtsGoodsSpecification goodsSpecification = new DtsGoodsSpecification();
        goodsSpecification.setDeleted(false);
        LambdaQueryWrapper<DtsGoodsSpecification> qw = new LambdaQueryWrapper<>();
        qw.eq(DtsGoodsSpecification::getGoodsId,id);
        goodsSpecificationMapper.update(goodsSpecification,qw);
    }

    @Override
    public void insert(Integer id, DtsGoodsSpecification[] specifications) {
        if(specifications != null && specifications.length>0){
            for (DtsGoodsSpecification specification : specifications) {
                specification.setDeleted(false);
                specification.setGoodsId(id);
                specification.setUpdateTime(new Date());
                specification.setAddTime(new Date());
                goodsSpecificationMapper.insert(specification);
            }
        }
    }
}
